<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/grsun" prefix="grsun"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Mailbox with some customizations as described in docs" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%@ include file="/include/main_include.jsp"%>
<%@ include file="/include/form_include.jsp"%>
 
</head>
<body>
	<div class="modal-body" style="max-height: 716px;">
		<div id="divform" class="row mx-dialog-c bs_dialog open"> 
		   <form id="dataForm" class="form-horizontal" method="post"> 
		   <input type="hidden" id="businessParentId" name="businessParentId" value="${pd.businessParentId}"/>   
			 
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">名称</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="name" name="name" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.name}">
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">联系人</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="contract" name="contract" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.contract}">
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">联系人电话</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="contractPhone" name="contractPhone" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.contractPhone}">
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">年费</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="yearFee" name="yearFee" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.yearFee}">
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">地址</label>
		        <div class="mx-group-control" style="height:33px;">
					<input id="address" name="address" type="text" class="width-100 mx-input-group" style="height:33px;" value="${pd.address}">
		        </div>
		    </div>
		    <%-- <div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">到期时间</label>
		        <div class="mx-group-control" style="height:33px;">
		        <input id="lastDate" class="easyui-datebox" name="lastDateText"   data-options="required:true,showSeconds:false"  value="${pd.lastDateText}"  style="width:150px">
		        </div>
		    </div> --%>
		 <div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">税务登记证明</label>
		        <div class="mx-group-control" style="height:100px;">
				        <div class="layui-upload">
				        <input type="hidden"  name="taxProve"  id="hide1"  value="${pd.taxProve}">
						 <input class="layui-upload-file" type="file" accept="images" name="file">
						  <div class="layui-upload-list">
						    <img class="layui-upload-img" id="test1" src="${imagePath}${pd.taxProve}">
						    <p id="demoText1"></p>
						  </div>
						</div> 
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">工商登记证明</label>
		         <div class="mx-group-control" style="height:100px;">
				        <div class="layui-upload">
						 <input class="layui-upload-file" type="file" accept="images" name="file">
						 <input type="hidden"  name="businessProve"  id="hide2"  value="${pd.businessProve}">
						  <div class="layui-upload-list">
						    <img class="layui-upload-img" id="test2" src="${imagePath}${pd.businessProve}">
						    <p id="demoText2"></p>
						  </div>
						</div> 
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">身份证正面</label>
		        <div class="mx-group-control" style="height:100px;">
				        <div class="layui-upload">
						 <input class="layui-upload-file" type="file" accept="images" name="file">
						 <input type="hidden"  name="card"   id="hide3" value="${pd.card}">
						  <div class="layui-upload-list">
						    <img class="layui-upload-img" id="test3" src="${imagePath}${pd.card}" >
						    <p id="demoText3"></p>
						  </div>
						</div> 
		        </div>
		    </div>
			<div class="form-group col-lg-6 col-sm-6 col-xs-6">
		        <label class="control-label mx-group-title">身份证反面</label>
		         <div class="mx-group-control" style="height:100px;">
				        <div class="layui-upload">
						 <input class="layui-upload-file" type="file" accept="images" name="file">
						 <input type="hidden"  name="cardReverse"  id="hide4"  value="${pd.cardReverse}">
						  <div class="layui-upload-list">
						    <img class="layui-upload-img" id="test4" src="${imagePath}${pd.cardReverse}">
						    <p id="demoText4"></p>
						  </div>
						</div> 
		        </div>
		    </div>
			 
		  </form>                  
		</div>
	</div>
	<script type="text/javascript">
	 function uploadFile(upload,flag){
		 upload.render({
			    elem: '#test'+flag
			    ,size:10000
			    ,url: '${path}/image/upload.do?path=business'
		    	,before: function(obj){
		    	      //预读本地文件示例，不支持ie8
		    	      obj.preview(function(index, file, result){
		    	        $('#test'+flag).attr('src', result); //图片链接（base64）
		    	      });
		    	 }
	    	    ,done: function(res){
	    	      //如果上传失败
	    	      if(res.code > 0){
	    	        return layer.msg('上传失败');
	    	      }else{
		    	      //上传成功
					$("#hide"+flag).val(res.url);	    	 
					return layer.msg('上传成功');
	    	      }
	    	    }
		 	});
	 }
	
	$(function() {
		layui.use('upload', function(){
			  var $ = layui.jquery;
			  upload = layui.upload;
			  uploadFile(upload,1);
			  uploadFile(upload,2);
			  uploadFile(upload,3);
			  uploadFile(upload,4);
		  });
		
		
		$('#dataForm').validate({
			submitHandler : function(form) {
				var index = parent.layer.getFrameIndex(window.name);
				$.uitools.showLoading();//打开处理中遮罩层
				$.ajax({
					cache : true,
					type : "POST",
					url : rootpath + '/hhBusinessParent/save.do',
					data : $('#dataForm').serialize(),
					error : function(request) {
						$.uitools.hideLoading();//关闭处理中遮罩层
						layer.msg('系统异常！', {
							icon : 2,
							time : 1000
						}, function() {
							parent.layer.close(index);
						})
					},
					success : function(data) {
						$.uitools.hideLoading();//关闭处理中遮罩层
						if (data.code==0) {
							layer.msg('提交成功！', {
								icon : 1,
								time : 1000
							}, function() {
								parent.layer.close(index);
								//刷新列表
								parent.dataTable.datagrid('reload');
							})
						} else {
							layer.msg('提交异常！', {
								icon : 2,
								time : 1000
							}, function() {
								parent.layer.close(index);
							})
						}
					}
				});
			},
			rules : {
				businessParentId : { required : true },
				name : { required : true },
				contract : { required : true },
				contractPhone : { required : true },
				yearFee : { required : true },
				address : { required : true },
				lastDate : { required : true ,number : true},
				card : { required : true },
				cardReverse : { required : true },
				businessProve : { required : true },
				taxProve : { required : true },
				agentId : { required : true },
				agentName : { required : true },
				status : { required : true ,number : true},
				addTime : { required : true ,number : true}
			},
			messages : {
				businessParentId : { required : '请输入' },
				name : { required : '请输入名称' },
				contract : { required : '请输入联系人' },
				contractPhone : { required : '请输入联系人电话' },
				yearFee : { required : '请输入年费' },
				address : { required : '请输入地址' },
				lastDate : { required : '请输入时间' },
				card : { required : '请输入身份证正面' },
				cardReverse : { required : '请输入身份证反面' },
				businessProve : { required : '请输入营业执照' },
				taxProve : { required : '请输入税务证明' },
				agentId : { required : '请输入' },
				agentName : { required : '请输入名称' },
				status : { required : '请输入状态' },
				addTime : { required : '请输入添加时间' }
			},
			// 失去焦点时不执行验证
			onfocusout : false,
			// 错误提示，错误对象
			errorPlacement : function(error, element) {
				// 1.错误信息，2提示位置，3同时提示多个错误
				layer.tips(error[0].innerText, element, {
					// 错误信息可以同时提示多个，...
					tipsMore : true,
					tips : [ 3, '#D16E6C' ]
				});
			}
		});
	});
	</script>
</body>
</html>
